
package com.eshop.we.business.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.eshop.we.business.BaseBusinessImpl;
import com.eshop.we.business.ExchangeOrderDetailBusiness;
import com.eshop.we.exchangeorder.api.ExchangeOrderService;
import com.eshop.we.exchangeorder.dto.ExchangeOrderDto;
import com.eshop.we.exchangeorder.entity.ExchangeOrder;
import com.eshop.we.exchangeorderdetail.api.ExchangeOrderDetailService;
import com.eshop.we.exchangeorderdetail.dto.ExchangeOrderDetailDto;
import com.eshop.we.exchangeorderdetail.entity.ExchangeOrderDetail;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wangzhanguo
 * @create 2018-06-04 15:31
 **/
@Service
public class ExchangeOrderDetailBusinessImpl extends BaseBusinessImpl<ExchangeOrderDetail,ExchangeOrderDetailService> implements ExchangeOrderDetailBusiness{
    @Reference
    private ExchangeOrderDetailService exchangeOrderDetailService;

    @Reference
    private ExchangeOrderService exchangeOrderService;
    @Override
    public List<ExchangeOrderDto> selectExchangeRecord(Integer userId) {
        return exchangeOrderDetailService.selectExchangeRecord(userId);
    }

    @Override
    public ExchangeOrderDetailDto selectOrderDetail(Integer orderId,Integer userId) {
        List<ExchangeOrderDetail> dList= exchangeOrderDetailService.selectList(new EntityWrapper<ExchangeOrderDetail>().eq("order_id",orderId));
        ExchangeOrder order=new ExchangeOrder();
        order.setId(orderId);
        ExchangeOrder exchangeOrder=exchangeOrderService.selectById(order);
        ExchangeOrderDetailDto dto=new ExchangeOrderDetailDto();
        BeanUtils.copyProperties(order,dto);
        for(ExchangeOrderDetail detail :dList ){
            if(detail.getUserId()==userId){
                dto.setaDetail(detail);
            }else{
                dto.setbDetail(detail);
            }
        }
        return  dto;
    }
}

